<?php
/**
 * @Author: Ron Chen
 * @Date:   2017-07-19 22:16:57
 * @Last Modified by:   Ron Chen
 * @Last Modified time: 2017-07-20 21:14:12
 */

namespace app\services;

use Yii;
use yii\web\Response;
use app\models\InsurancePolicy;

use Qiniu\Auth;
use Qiniu\Storage\UploadManager;
/**
* 对象存储相关服务
*/
class QiniuService
{
	private $oss;
	private $bucket = 'funfind';
	private $token;

	public function __construct(){
		require_once '../common/qiniu/autoload.php';
		
		$accessKey = 'oofK2AFVHgI0AXYI90u6XKOb-PyFn6o5EexKaY7b';
		$secretKey = 'VgOUXKXYTp8OgxcA3v3VZgm5rIb4IdjkVIBhpgll';

		$auth = new Auth($accessKey, $secretKey);
		$this->token = $auth->uploadToken($this->bucket);

	}

	public function uploadFile($object,$data){
		$uploadMgr = new UploadManager();
		list($ret, $err) = $uploadMgr->put($this->token, $object, $data);
		if ($err !== null) {
		    var_dump($err);
		} else {
		    var_dump($ret);
		}
	}


}